import 'package:json_annotation/json_annotation.dart';

part 'get_article_res.g.dart';

@JsonSerializable(fieldRename: FieldRename.none)
class GetArticleRes {
  final int? code;
  final Data? data;
  final String? msg;

  const GetArticleRes({
    this.code,
    this.data,
    this.msg,
  });

  factory GetArticleRes.fromJson(Map<String, dynamic> json) =>
      _$GetArticleResFromJson(json);

  Map<String, dynamic> toJson() => _$GetArticleResToJson(this);

  GetArticleRes copyWith({
    int? code,
    Data? data,
    String? msg,
  }) {
    return GetArticleRes(
      code: code ?? this.code,
      data: data ?? this.data,
      msg: msg ?? this.msg,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class Data {
  final List<ArticleModel>? list;
  final int? total;

  const Data({
    this.list,
    this.total,
  });

  factory Data.fromJson(Map<String, dynamic> json) =>
      _$DataFromJson(json);

  Map<String, dynamic> toJson() => _$DataToJson(this);

  Data copyWith({
    List<ArticleModel>? list,
    int? total,
  }) {
    return Data(
      list: list ?? this.list,
      total: total ?? this.total,
    );
  }
}

@JsonSerializable(fieldRename: FieldRename.none)
class ArticleModel {
  final int? id;
  final String? title;
  final String? content;
  final String? author;
  final int? publishTime;
  final String? category;
  final int? createTime;

  const ArticleModel({
    this.id,
    this.title,
    this.content,
    this.author,
    this.publishTime,
    this.category,
    this.createTime,
  });

  factory ArticleModel.fromJson(Map<String, dynamic> json) =>
      _$ArticleModelFromJson(json);

  Map<String, dynamic> toJson() => _$ArticleModelToJson(this);

  ArticleModel copyWith({
    int? id,
    String? title,
    String? content,
    String? author,
    int? publishTime,
    String? category,
    int? createTime,
  }) {
    return ArticleModel(
      id: id ?? this.id,
      title: title ?? this.title,
      content: content ?? this.content,
      author: author ?? this.author,
      publishTime: publishTime ?? this.publishTime,
      category: category ?? this.category,
      createTime: createTime ?? this.createTime,
    );
  }
}
